<template>
  <view class="order-goods-bill">
    <navigator :url="`/pages/category/goodsDetail?id=${item.id_}`" class="product" v-for="item in list" :key="item.id_">
      <image class="product_img" :src="item.main_img_" mode="aspectFill" />
      <view>
        <view class="product_name ellipsis">{{ item.name_ }}</view>
        <view class="product_code_stock">
          <view class="product_footer">
            编号：{{ item.code_ }}
          </view>
          <view class="product_footer">
            规格：{{ item.productList.length }}
          </view>
          <view class="product_footer">
            库存：{{ item.stock_ }}
          </view>
        </view>
        <view class="spu_goods_footer">
          <text class="spu_goods_price">￥{{ item.market_price_.toFixed(2) }}起</text>
          <view class="icon-cart-container" @tap.stop="checkSpec(item)">
            <text class="iconfont icon-cart"></text>
          </view>
        </view>
      </view>
    </navigator>
    <PinSkuPanel ref="skuPanel" :isNoBar="false" />
  </view>
</template>

<script lang="ts" setup>
import type { commonItem } from "@/types/user"
import { onMounted, ref } from "vue"
import Apis from "@/services/modules/user"
import type { PinSkuPanelInstance } from "@/types/component";

onMounted(() => {
  getFavoriteGoodsListData()
})

const list = ref<commonItem[]>([])
const getFavoriteGoodsListData = async () => {
  const { data } = await Apis.getFavoriteGoodsList()
  list.value = data.pdList || []
}

const skuPanel = ref<PinSkuPanelInstance>()
const checkSpec = async (item: commonItem) => {
  await skuPanel.value?.getData(`${item.id_}`)
}

</script>

<style lang="scss">
page {
  background: #f6f6f6;
}

.order-goods-bill {
  padding: 12px;

  .product {
    margin-bottom: 12px;
    background-color: #fff;
    display: flex;
    padding: 4px;
    border-radius: 4px;

    .product_img {
      width: 128px;
      height: 108px;
      margin-right: 6px;
      border-radius: 4px;
    }

    .product_name {
      $padding: 4px;
      padding: $padding ;
      width: calc(100% - 2 * $padding);
      font-size: 14px;
    }

    .product_code_stock {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .product_footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 2px;
        font-size: 14px;
        color: $uni-text-color-grey;
      }
    }

    .spu_goods_footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 4px;

      .spu_goods_price {
        color: red;
        font-size: 18px;
      }

      .icon-cart-container {
        $wh: 30px;
        width: $wh;
        height: $wh;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: $uni-color-warning;

        .icon-cart {
          color: #fff;
          // font-size: 20px;
          // font-weight: bold;
        }
      }
    }
  }
}
</style>
